﻿using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Functions;
using MinimalistFoodStreet.BackEnd.Server.IServer.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers
{
    [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.business })]
    public class SearchRecordController : BaseController
    {
        private readonly ISearchRecordServer _searchRecordServer;

        public SearchRecordController(ISearchRecordServer searchRecordServer)
        {
            _searchRecordServer = searchRecordServer;
        }
        /// <summary>
        /// 添加搜素记录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add(RequestSearchRecordAddDto dto)
        {
            return Send(await _searchRecordServer.AddAsync(dto, _business.BId));
        }
        /// <summary>
        /// 删除指定的搜素记录
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete(RequestSearchRecordDeleteDto dto)
        {
            return Send(await _searchRecordServer.DeleteAsync(dto, _business.BId));
        }
        /// <summary>
        /// 清空搜素记录
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ClearAll()
        {
            return Send(await _searchRecordServer.ClearAllAsync(_business.BId));
        }
        /// <summary>
        /// 获取全部搜素记录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetAll()
        {
            return Send(await _searchRecordServer.GetAllAsync(_business.BId));
        }
    }
}
